<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>填写日志</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="../../css/mui.min.css">
		<link rel="stylesheet" href="../../css/global.css">
		<link rel="stylesheet" href="../../css/style.css">
		<style type="text/css">
			input.d_ipt {
				width: 54%;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="title" class="mui-title">填写日志</h1>
		</header>
		<div class="mui-content">
			<div class="details_con" id="form_info">
				<input type="hidden" id="dataId" />
				<div class="clum">
					<span class="name">接受任务时间</span>
					<input type="text" class="d_ipt" id="acceptTime" name="acceptTime" disabled="disabled"/>
				</div>
				<div class="clum">
					<span class="name">出发时间<em class="t_red">*</em></span>
					<input type="text" class="d_ipt" id="departureTime" name="departureTime" required="required" readonly="readonly" placeholder="请选择出发时间" />
				</div>
				<div class="clum">
					<span class="name">到达现场时间<em class="t_red">*</em></span>
					<input type="text" class="d_ipt" id="arriveTime" name="arriveTime" required="required" readonly="readonly" placeholder="请选择到达现场时间" />
				</div>
				<div class="clum">
					<span class="name">工作开始时间<em class="t_red">*</em></span>
					<input type="text" class="d_ipt" id="startTime" name="startTime" required="required" readonly="readonly" placeholder="请选择开始时间" />
				</div>
				<div class="clum">
					<span class="name">工作结束时间<em class="t_red">*</em></span>
					<input type="text" class="d_ipt" id="endTime" name="endTime" required="required" readonly="readonly" placeholder="请选择结束时间" />
				</div>
				<div class="clum">
					<span class="name">工作小时数<em class="t_red">*</em></span>
					<input type="number" class="d_ipt" id="workHour" name="workHour" required="required" maxlength="4" placeholder="请输入工作小时数" />
				</div>
				<div class="clum">
					<span class="name">旅途小时数<em class="t_red">*</em></span>
					<input type="number" class="d_ipt" id="journeyHour" name="journeyHour" required="required" maxlength="4" placeholder="请输入旅途小时数" />
				</div>
				<div class="clum nobor autoHeight">
					<span class="name">工作内容<em class="t_red">*</em></span>
					<div class="clear"></div>
					<textarea class="textarea" id="workContent" name="workContent" required="required" maxlength="500" placeholder="请输入工作内容"></textarea>				
				</div>
			</div>
			<div class="btn_box">
				<span class="fl" id="cancale">取消</span>
				<span class="fr red" id="submitBtn">保存</span>
			</div>
			<div style="height: 50px;"></div>
		</div>

		<!-- js代码 start -->

		<!-- 基础js start -->
		<script src="../../js/mui.min.js"></script>
		<script src="../../js/utils/h.js"></script>
		<script src="../../js/constant.js"></script>
		<script src="../../js/common.js"></script>
		<script src="../../js/utils/base64.js"></script>
		<script src="../../js/utils/md5.js"></script>
		<script src="../../js/utils/sortMap.js"></script>
		<script src="../../js/utils/http.js"></script>
		<script src="../../js/app.js"></script>
		<script src="../../js/sqliteTools.js"></script>
		<!-- 基础js end -->
		<script src="../../js/utils/rolldate.min.js"></script>
		<script src="../../js/fse/service/serviceLog/log.js"></script>
		<script type="text/javascript" charset="utf-8">
			(function($, doc) {
				$.init();
		
				$.plusReady(function() {			
					var self = plus.webview.currentWebview();
					var data = self.data;
					h('#dataId').val(data.id);
					h('#acceptTime').val(data.acceptTime || '');
					h('#arriveTime').val(data.signInTime.substring(0, data.signInTime.length-3) || '');
					if (!JS.IsNullOrEmpty(data.departureTime)) {
						h('#departureTime').val(data.departureTime)
					}
					if (!JS.IsNullOrEmpty(data.startTime)) {
						h('#startTime').val(data.startTime)
					}
					if (!JS.IsNullOrEmpty(data.endTime)) {
						h('#endTime').val(data.endTime)
					}
					if (!JS.IsNullOrEmpty(data.workHour)) {
						h('#workHour').val(data.workHour)
					}
					if (!JS.IsNullOrEmpty(data.journeyHour)) {
						h('#journeyHour').val(data.journeyHour)
					}
					if (!JS.IsNullOrEmpty(data.workContent)) {
						h('#workContent').val(data.workContent)
					}
										
					initDateTimeControls()
					
					// 提交保存
					h('#submitBtn').tap(function() {
						var dataId = h('#dataId').val();
						var acceptTime = h('#acceptTime').val();
						var arriveTime = h('#arriveTime').val();
						var departureTime = h('#departureTime').val()
						var startTime = h('#startTime').val()
						var endTime = h('#endTime').val()
						var workHour = h('#workHour').val()
						var journeyHour = h('#journeyHour').val()
						var workContent = h('#workContent').val()
						if (!departureTime) {
							app.toast("请选择出发时间")
							return;
						}
						if (stringYYYYMMDDHHMMToDate(acceptTime).getTime() > stringYYYYMMDDHHMMToDate(departureTime).getTime()) {
							app.toast("出发时间不能小于接受任务时间")
							return false
						}
						if (!startTime) {
							app.toast("请选择工作开始时间")
							return false;
						}
						if (stringYYYYMMDDHHMMToDate(startTime).getTime() < stringYYYYMMDDHHMMToDate(arriveTime).getTime()) {
							app.toast("工作开始时间不能小于到达现场时间")
							return false
						}
						if (!endTime) {
							app.toast("请选择工作结束时间")
							return false;
						}
						if (stringYYYYMMDDHHMMToDate(startTime).getTime() > stringYYYYMMDDHHMMToDate(endTime).getTime()) {
							app.toast("工作开始时间不能大于工作结束时间")
							return false
						}
						if (!workHour) {
							app.toast("请输入工作小时数")
							return false;
						}
						if (!journeyHour) {
							app.toast("请输入旅途小时数")
							return false;
						}
						if (!workContent) {
							app.toast("请输入工作内容")
							return false;
						}
						var newDate = new Date().getTime(); // 当前时间
						if (stringYYYYMMDDHHMMToDate(departureTime).getTime() > newDate) {
							app.toast('出发时间不能大于当前时间')
							return false
						}

						if (stringYYYYMMDDHHMMToDate(arriveTime).getTime() > newDate) {
							app.toast('到达现场时间不能大于当前时间')
							return false
						}

						if (stringYYYYMMDDHHMMToDate(startTime).getTime() > newDate) {
							app.toast('工作开始时间不能大于当前时间')
							return false
						}

						if (stringYYYYMMDDHHMMToDate(endTime).getTime() > newDate) {
							app.toast('工作结束时间不能大于当前时间')
							return false
						}
						// 非负数校验
						var patt = /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/
						if (patt.test(workHour) == false) {
							app.toast("请输入有效工作小时数");
							return false;
						}
						if (patt.test(journeyHour) == false) {
							app.toast("请输入有效旅途小时数");
							return false;
						}

						if(Number(workHour)>Number(gztimes)){
							app.toast("工作小时数，不能大于（工作结束时间-工作开始时间）");
							return false;
						}

						/* if(Number(journeyHour)>Number(lttimes)){
							app.toast("旅途小时数，不能大于（到达现场时间-出发时间）");
							return false;
						} */

						var sqliteTool = new sqliteTools();
						sqliteTool.openDatabase()
						sqliteTool.insertServiceWorkingLogData(dataId, departureTime, startTime, endTime, workHour, journeyHour, workContent, function(flag) {
							if (!flag) {
								app.toast("保存失败");
								return;
							}
							app.toast("保存成功");
							// 1、刷新列表
							var offlineList = plus.webview.getWebviewById('view/offline/list.html');
							if (offlineList) {
								offlineList.evalJS('initData()');
							}
							$.back();
						})
					});
					
					h('#cancale').tap(function() {
						$.back();
					})
					
				});
			}(mui, document));		
		</script>		
		<!-- js代码 end -->
	</body>
</html>

